package com.wen.controller;

import com.wen.common.ResultDtoFactory;
import com.wen.common.constant.MsgCode;
import com.wen.common.constant.MsgCodeEnum;
import com.wen.common.constant.OrderCodeEnum;
import com.wen.domain.User;
import com.wen.common.ResultDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * 测试
 */
@Controller
@RequestMapping("test")
public class TestController {

    @RequestMapping("index")
    public ModelAndView index() {
        User user = new User();
        user.setId(23l);
        user.setAddress("江干区");
        user.setCreateDate(new Date());

        ModelAndView modelAndView = new ModelAndView("test/index");
        modelAndView.addObject("data", user);

        return modelAndView;
    }

    /**
     * 测试枚举返回json
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("er")
    public ResultDto er() {
        ResultDto resultDto = ResultDtoFactory.success();

        return resultDto;
    }

    /**
     * 测试枚举返回json
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("su")
    public ResultDto su(int type) {
        if (type == 1) {
            ResultDto resultDto = ResultDtoFactory.success("登录成功");
             resultDto = ResultDtoFactory.success("登录成功89898");

            return resultDto;
        } else {
            return ResultDtoFactory.success("帐号已经登陆！");
        }
    }


    /**
     * 测试枚举返回json
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("enum")
    public ResultDto enumJson() {
        OrderCodeEnum msgCode = OrderCodeEnum.CANCEL;
        ResultDto resultDto = ResultDtoFactory.ERROR(msgCode);
        resultDto.setMessage("你谁啊");

        return resultDto;
    }
}
